/**
 * @author Matthew.He
 */
package com.iot.ic.modules.util;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Matthew.He
 *
 */
public class RequestUtil {

	public static Map getRequestMap(HttpServletRequest request) {
		Map<String,Object> map = new HashMap<>();
		Enumeration enu = request.getParameterNames();

		while (enu.hasMoreElements()) {
			Object name = enu.nextElement();
			Object value = request.getParameter(name.toString());

			map.put(name.toString(), value == null ? null : value.toString());
		}

		return map;
	}

	/**
	 * 有值情况正常返回,无值则直接返回NULL
	 * 
	 * @author Matthew.He
	 * @param map
	 * @param key
	 * @return
	 */
	public static String getValue(Map map, String key) {
		return map.get(key) == null ? null : map.get(key).toString();
	}

	public static Object getObjValue(Map map, String key) {
		return map.get(key) == null ? null : map.get(key);
	}
}
